package shop.up.cart.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import shop.up.cart.client.impl.CartDegradeFeignClient;
import shop.up.common.result.Result;
import shop.up.model.cart.CartInfo;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zzc
 * @date 2023/4/12 22:07
 */
@FeignClient(value = "service-cart", fallback = CartDegradeFeignClient.class)
public interface CartFeignClient {
    /**
     * 添加购物车
     * @param skuId
     * @param skuNum
     * @return
     */
    @PostMapping("/api/cart/addToCart/{skuId}/{skuNum}")
    Result addToCart(@PathVariable("skuId") Long skuId, @PathVariable("skuNum") Integer skuNum);

    /**
     * 查询购物车
     * @param request
     * @return
     */
    @GetMapping("/api/cart/cartList")
    Result cartList(HttpServletRequest request);

    /**
     * 更新选中状态
     * @param skuId
     * @param isChecked
     * @param request
     * @return
     */
    @GetMapping("/api/cart/checkCart/{skuId}/{isChecked}")
    Result checkCart(@PathVariable(value = "skuId") Long skuId,
                            @PathVariable(value = "isChecked") Integer isChecked, HttpServletRequest request);

    /**
     * 删除登录用户购物车中指定skuId的商品
     * @param skuId
     * @param request
     * @return
     */
    @DeleteMapping("/api/cart/deleteCart/{skuId}")
    Result deleteCart(@PathVariable("skuId") Long skuId,
                             HttpServletRequest request);

    /**
     * 查数据库存缓存
     * @param userId
     * @return
     */
    @GetMapping("/api/cart/loadCartCache/{userId}")
    Result loadCartCache(@PathVariable("userId") String userId);

    /**
     * 根据用户Id 查询购物车列表
     * @param userId
     * @return
     */
    @GetMapping("/api/cart/getCartCheckedList/{userId}")
    List<CartInfo> getCartCheckedList(@PathVariable("userId") String userId);
}
